package com.yc.wxcontroller;

import com.yc.service.ScheduleService;
import com.yc.service.impl.WxScheduleServiceImp;
import com.yc.vo.Result;
import com.yc.vo.ScheduleVo;
import com.yc.vo.StudentAttendanceRecord;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

/**
 * @author zxy
 * @version 1.0
 * @description: TODO
 * @date 2023/7/24 11:03
 */
@Api("微信管理课程表控制器")
@RestController
@RequestMapping("/wx/schedule")
public class WXScheduleController {

    @Resource
    private WxScheduleServiceImp wxScheduleServiceImp;
    @Autowired
    private ScheduleService scheduleService;

    /**
     * 查询学年
     * @return
     */
    @PostMapping("/selectschoolyear")
    public List<Map<String,Object>> selectschoolyear(){
        return wxScheduleServiceImp.selectschoolyear();
    }

    /**
     * 通过当天日期查询当前是哪个周次和学年
     * @param day
     * @return
     */
    @PostMapping("/selectwhichweekandyear")
    public Map<String, Object> selectwhichweekandyear(String day){
        return wxScheduleServiceImp.selectwhichweekandyear(day);
    }

    /**
     * 通过传入当天日期来查询 所在的学期 和 所在的周次 和 当周的全部日期
     * @param day
     * @return
     */
    @PostMapping("/selectdayyearweek")
    public Map<String,Object> selectdayyearweek(String day){
        return wxScheduleServiceImp.selectdayyearweek(day);
    }

    /**
     * 通过学生id和周次查询该周全部课程
     * @param stuid
     * @param week
     * @return
     * @throws ParseException
     */
    @PostMapping("/selectstuclassbyweek")
    public List<Map<String,Object>> selectstuclassbyweek(String stuid,String week) throws ParseException {
        return wxScheduleServiceImp.selectstuclass(stuid,week);
    }

    /**
     * 通过老师id和周次查询该周全部课程
     * @param tid
     * @param week
     * @return
     * @throws ParseException
     */
    @PostMapping("/selectteacherclass")
    public List<Map<String,Object>> selectteacherclass(String tid,String week) throws ParseException {
        return wxScheduleServiceImp.selectteacherclass(tid,week);
    }

    /**
     * 通过周次学年查询该学年该周次下的日期
     * @param week
     * @param year
     * @return
     */
    @PostMapping("/selectdaybyweek")
    public List<String> selectdaybyweek(String week, String year){
        return wxScheduleServiceImp.selectdaybyweek(week, year);
    }


    @ApiOperation("查询当前老师今天所有课程")
    @PostMapping("/findsutas")
    public Result findSystemUerTodayAllSchedule(String username){
        List<ScheduleVo> list = scheduleService.findSystemUerTodayAllSchedule(username);
        if(null == list || list.isEmpty()){
            return Result.error("暂无课程!");
        }else{
            return Result.success(list);
        }
    }

    @ApiOperation("根据老师Id查询上课信息")
    @GetMapping("/schedule/get/{teacherId}")
    public Result selectScheduleByTeacherId(@ApiParam(name = "teacherId", value = "老师Id", required = true)
                                            @PathVariable("teacherId") String teacherId){
        List<StudentAttendanceRecord> studentAttendanceRecords = scheduleService.selectScheduleByTeacherId(teacherId);
        return Result.success(studentAttendanceRecords);
    }
}
